package sgbag1.Vues;

import java.awt.Color;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;

import java.awt.Rectangle;

import java.awt.geom.Point2D;

import sgbag1.Noyau.Chariot;
import sgbag1.Noyau.Global;

public class VueChariot extends VueElement {
    
    private int rayon = 10;
    private Chariot chariot;
    private Color couleurLibre = new Color(0, 139, 0);
    private Color couleurOccupe = new Color(220, 20, 60);
    
    public VueChariot(Chariot c){
        super(new Point((int)c.getPosition().getX(), (int)c.getPosition().getY()));
        chariot = c;
    }
    
    public VueChariot(){
        super();
    }
    
    public Chariot getObjetNoyau(){
        return chariot;
    }
    
    @Override
    public void Dessiner(Graphics g){
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(couleurLibre);
        
        if(chariot.getEtat() == Global.LIBRE || chariot.getEtat() == Global.AU_GARARE){
            g2.setColor(couleurLibre);
        }
        else if(chariot.getEtat() == Global.OCCUPE){
            g2.setColor(couleurOccupe);
        }
        
        position = new Point((int)chariot.getPosition().getX(), (int)chariot.getPosition().getY());
        position.setLocation(position.getX()*tauxConversion, position.getY()*tauxConversion);

        position.setLocation(position.getX()+decalage.getX(), position.getY()+decalage.getY());

        this.CalculerBoiteEnglobante();
        g2.fillOval((int)position.getX() - rayon, (int)position.getY() - rayon, 2 * rayon, 2 * rayon);
        g2.setColor(new Color(0,0,0));
        g2.drawString(""+chariot.getId(), position.x - 4, position.y + 3);
        super.Dessiner(g);
    }
    
    @Override
    public void CalculerBoiteEnglobante() {
        boiteEnglobante = new Rectangle((int)position.getX() - rayon, (int)position.getY() - rayon, 2 * rayon, 2 * rayon);
    }
}
